﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Fjaspx.DB;
using System.Text;
using Fjaspx.Common;

namespace Fjaspx.UI.Web
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 图片文章
        /// </summary>
        /// <returns></returns>
        public DataSet GetChannel1()
        {
            string Sql = "select top 5 * from Fjaspx_Article where IsTop=1 and IsImg=1 and Passed=1 order by ArtDate desc";
            return DbHelperSQL.Query(Sql);
        }
        /// <summary>
        /// 新闻中心
        /// </summary>
        /// <returns></returns>
        public DataSet GetChannel2()
        {
            string Sql = "select top 8 * from Fjaspx_Article where CatId in(select  orderId from Fjaspx_ArticleCategory where ChannelId=11 and show=0 and IsMenu=0) order by ArtDate desc";
            return DbHelperSQL.Query(Sql);
        }
        //频道
        public Fjaspx.Sys.Model.Fjaspx_Channel GetChannel(string channelId)
        {
            return new Fjaspx.Sys.Bll.Fjaspx_Channel().GetModel(int.Parse(channelId));
            // return new Fjaspx.Sys.Bll.Fjaspx_ArticleCategory().GetList("ChannelId=" + channelId + "", 1);
        }
        //类别列表
        public DataSet GetCategorys(string channelId)
        {
            return new Fjaspx.Sys.Bll.Fjaspx_ArticleCategory().GetList("ChannelId=" + channelId + "", 4);
        }

        //频道图片文章
        public DataSet GetChannelImg(string channelId)
        {
            return new Fjaspx.Sys.Bll.Fjaspx_Article().GetList("ChannelId=" + channelId + " order by artDate desc", 2);
        }
        //频道文字文章
        public DataSet GetChannelArticle(string categoryId)
        {
            return new Fjaspx.Sys.Bll.Fjaspx_Article().GetList("ChannelId=" + categoryId + "", 10);
        }

        //频道HTML
        public string ChannelHtml(string channelId)
        {
            StringBuilder str = new StringBuilder();
            str.Append("<table class=\"classshowbox\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" border=\"0\">");
            DataSet datasetChannel = GetCategorys(channelId);
            Fjaspx.Sys.Model.Fjaspx_Channel channel = GetChannel(channelId);
            if (channel != null)
            {
                str.Append("<tr>");
                str.Append("<td class=\"main_title_282i\" colspan=\"2\">");
                str.Append("<a href=\"Article/List_" + channel.OrderId + ".html\"><strong>" + channel.ChannelName + "</strong></a>");
                str.Append("</td>");
                str.Append("</tr>");
                str.Append("<tr>");
                str.Append("<td class=\"main_tdbg_282i\" align=\"middle\" width=\"110\">");
                str.Append("<table width='100%' cellpadding='0' cellspacing='5' border='0' align='center'>");
                DataSet datasetChannelImg1 = GetChannelImg(channel.OrderId.ToString());
                if (datasetChannelImg1.Tables[0].Rows.Count > 0)
                {
                    for (int k = 0; k <= datasetChannelImg1.Tables[0].Rows.Count - 1; k++)
                    {
                        str.Append("<tr valign='top'>");
                        str.Append("<td align='center'>");
                        str.Append("<a class=\"\" href=\"Article/Article.aspx?Id=" + datasetChannelImg1.Tables[0].Rows[k]["OrderId"].ToString() + "\" title=\"" + datasetChannelImg1.Tables[0].Rows[k]["ArtTitle"].ToString() + "\" target=\"_blank\">");
                        str.Append("<img class='pic1' src='" + ResolveUrl("~/" + datasetChannelImg1.Tables[0].Rows[k]["images"].ToString()) + "'  width='100' height='70' border='0'/></a>");
                        str.Append("</td>");
                        str.Append("</tr>");
                    }
                }
                str.Append("</table>");
                str.Append("</td>");
                str.Append("<td class=\"main_tdbg_282i\" valign=\"top\">");
                str.Append("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">");

                DataSet datasetChannelArticle1 = GetChannelArticle(channel.OrderId.ToString());
                if (datasetChannelArticle1.Tables[0].Rows.Count > 0)
                {
                    for (int k = 0; k <= datasetChannelArticle1.Tables[0].Rows.Count - 1; k++)
                    {
                        str.Append("<tr>");
                        str.Append("<td width=\"10\" valign=\"top\" class=\"\">");
                        str.Append("<img src=\"images/Article_common2.gif\" alt=\"普通文章\">");
                        str.Append("</td>");
                        str.Append("<td class=\"\">");
                        str.Append("[<a class=\"\" href=\"Article/List_" + datasetChannelArticle1.Tables[0].Rows[k]["CatId"].ToString() + ".html\">"
                         + new Fjaspx.Sys.Bll.Fjaspx_ArticleCategory().GetModel(int.Parse(datasetChannelArticle1.Tables[0].Rows[k]["CatId"].ToString())).CatName + "</a>]");
                        str.Append("<a class=\"\" href=\"Article/Article.aspx?Id=" + datasetChannelArticle1.Tables[0].Rows[k]["OrderId"].ToString() + "\" title=\"文章标题：" +
                            datasetChannelArticle1.Tables[0].Rows[k]["ArtTitle"].ToString() + "作&nbsp;&nbsp;&nbsp;&nbsp;者：" + datasetChannelArticle1.Tables[0].Rows[k]["ArtAuthor"].ToString() + "更新时间： " +
                            Convert.ToDateTime(datasetChannelArticle1.Tables[0].Rows[k]["ArtDate"]).ToString("yyyy-MM-dd") + "\" target=\"_self\">" +
                            StringHelper.CutString(datasetChannelArticle1.Tables[0].Rows[k]["ArtTitle"].ToString(), 26) + "</a>");
                        str.Append("</td>");
                        str.Append("</tr>");
                    }
                }
                str.Append("</table>");
                str.Append("</td>");
                str.Append("</tr>");

            }
            str.Append("</table>");
            return str.ToString();
        }

        //频道HTML
        public string ChannelHtmlNoImage(string channelId)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<table class=classshowbox style='WIDTH: 248px; HEIGHT: 51px' cellSpacing=0 cellPadding=0 width=248 border=0>");
            sb.Append("<tr>");
            sb.Append("<td class=main_title_282i colSpan=2><A href='soft/Index.html'><STRONG>数&nbsp; 据&nbsp; 库</STRONG></A></A></td>");
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td class=main_tdbg_282i align=middle colSpan=2>");
            sb.Append("<table width='100%' cellpadding='0' cellspacing='0'>");
            DataSet ds = new Fjaspx.Sys.Bll.Fjaspx_Article().GetList("CatId=" + channelId, 20);
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                {
                    sb.Append("<tr><td width='10' valign='top' class=''><img src='http://www.wzhan.net/Article/images/Article_ontop2.gif' alt='固顶文章'></td><td class=''>[<a class='' href='http://www.wzhan.net/Article/List_59.html'>MYSQL</a>]");
                    sb.Append("<a class='' href='http://www.wzhan.net/Article/11797.html' ");
                    sb.Append("title='文章标题：链接建设垂直策略or平行策略 作&nbsp;&nbsp;&nbsp;&nbsp;者：佚名 更新时间：2011-1-28 16:37:45' target='_self'>");
                    sb.Append("链接建设垂直策略or平行策略</a></td></tr>");
                }
            }

            sb.Append("<tr></tr></table>");
            sb.Append("<table width='100%' cellpadding='0' cellspacing='0'>");
            sb.Append("<tr><td width='10' valign='top' class=''><img src='http://www.wzhan.net/Soft/images/Soft_common4.gif' alt='普通软件'></td>");
            sb.Append("<td class=''><a class='' href='http://www.wzhan.net/Soft/67917.html' title='EnMp3Player破解版' target='_blank'>EnMp3Player破解版</a>");
            sb.Append("</td></tr>");
            sb.Append("<tr></tr></table>");
            sb.Append("<table width='100%' cellpadding='0' cellspacing='0'>");
            sb.Append("<tr><td width='10' valign='top' class=''><img src='http://www.wzhan.net/Article/images/Article_common2.gif' alt='普通文章'></td>");
            sb.Append("<td class=''>[<a class='' href='http://www.wzhan.net/Article/List_15.html'>网站备案</a>]<a class='' href='http://www.wzhan.net/Article/11499.html' title='文章标题：拍照备案只是浪费时间和成本而已 作&nbsp;&nbsp;&nbsp;&nbsp;者：佚名 更新时间：2010-12-27 12:43:25' target='_self'>");
            sb.Append("拍照备案只是浪费时间和成本而</a></td></tr>");
            sb.Append("<tr></tr></table>");
            sb.Append("</td>");
            sb.Append("</tr>");
            sb.Append("</table>");

            return sb.ToString();
        }

        #region"图片"
        public string ChannelImageHtml()
        {
            StringBuilder sb = new StringBuilder();
            List<Fjaspx.Sys.Model.Fjaspx_Photos> photosList = new Fjaspx.Sys.Bll.Fjaspx_Photos().GetList();
            sb.Append("<table width='100%' cellpadding='0' cellspacing='5' border='0' align='center'>");
            sb.Append("<tr valign='top'>");
            foreach (var model in photosList)
            {
                sb.Append("<td align='center'>");
                sb.Append("<a class=\"\" href=\"Photo/201.html\" title=\"" + model.Title + "\" target=\"_blank\">");
                sb.Append("<img class='pic3' src='" + model.PhotoId + "' width='130' height='90' border='0'></a><br>");
                sb.Append("<a class=\"\" href=\"Photo/" + model.PhotoId + ".html\" title=\"" + model.FileName + "\" target=\"_blank\">" + model.FileName + "</a>");
                sb.Append("</td>");
            }
            sb.Append("</tr>");
            sb.Append("</table>");
            return sb.ToString();
        }
        #endregion
        public string FriendLink()
        {
            StringBuilder sb = new StringBuilder();
            List<Fjaspx.Sys.Model.Fjaspx_FriendLink> list = new Fjaspx.Sys.Bll.Fjaspx_FriendLink().GetList();
            for (int i = 0; i <= list.Count - 1; i++)
            {
                sb.Append("<a title=\"" + list[0].FL_WebName + "\" href=\"" + list[0].FL_Url + "\">" + list[0].FL_WebName + "</a>&nbsp;&nbsp;&nbsp;&nbsp;");
            }
            return sb.ToString();
        }
        //常用软件
        public string UseSoft()
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i <= 4; i++)
            {
                sb.Append("<strong><font color=\"#444444\">&nbsp;论坛下载：</font></strong></br>&nbsp;");
                for (int j = 0; j <= 10; j++)
                {
                    sb.Append("<font color=\"#3c72c4\">PHPWind</font><font color=\"#3c72c4\"> |");
                }
            }
            return sb.ToString();
        }

        //最新文章
        public string getArticleNew()
        {
            StringBuilder sb = new StringBuilder();
            DataSet ds = new Fjaspx.Sys.Bll.Fjaspx_Article().GetList("1=1 order by artDate desc", 8);
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("<table cellspacing=\"3\" cellpadding=\"0\" width=\"100%\" border=\"0\">");
                for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                {
                    sb.Append("<tr class=\"leftline\">");
                    sb.Append("<td valign=\"top\" colspan=\"2\">");
                    sb.Append("<a href=\"Article/Article.aspx?Id=" + ds.Tables[0].Rows[i]["OrderId"].ToString() + "\">&nbsp; " + ds.Tables[0].Rows[i]["ArtTitle"].ToString() + "</a>");
                }
                sb.Append("</td>");
                sb.Append("</tr>");
                sb.Append("</table>");
            }
            return sb.ToString();
        }
        //推荐文章
        public string getArticleCommend()
        {
            StringBuilder sb = new StringBuilder();
            DataSet ds = new Fjaspx.Sys.Bll.Fjaspx_Article().GetList("Recommend=1 order by artDate desc", 8);
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("<table cellspacing=\"3\" cellpadding=\"0\" width=\"100%\" border=\"0\">");
                for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                {
                    sb.Append("<tr class=\"leftline\">");
                    sb.Append("<td valign=\"top\" colspan=\"2\">");
                    sb.Append("<a href=\"Article/Article.aspx?Id=" + ds.Tables[0].Rows[i]["OrderId"].ToString() + "\">&nbsp; " + ds.Tables[0].Rows[i]["ArtTitle"].ToString() + "</a>");
                }
                sb.Append("</td>");
                sb.Append("</tr>");
                sb.Append("</table>");
            }
            return sb.ToString();
        }

        //频道14, 站长周刊
        public string getArticletWeb()
        {
            StringBuilder sb = new StringBuilder();
            DataSet ds = DbHelperSQL.Query("select top 1 * from Fjaspx_Article where catId in(select OrderId from Fjaspx_ArticleCategory where ChannelId=14) order by artDate desc ");
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("<a href=\"Article/Article.aspx?Id=" + ds.Tables[0].Rows[0]["OrderId"].ToString() + "\">");
                sb.Append("<img class='pic1' src='" + ds.Tables[0].Rows[0]["images"].ToString() + "' width='180' height='214' border='0'></a>");
            }
            return sb.ToString();
        }

        //频道15, 视频教程
        public string getArticleVoid()
        {
            StringBuilder sb = new StringBuilder();
            DataSet ds = DbHelperSQL.Query("select top 8 * from Fjaspx_Article where catId in(select OrderId from Fjaspx_ArticleCategory where ChannelId=15) order by artDate desc ");
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("<table cellspacing=\"3\" cellpadding=\"0\" width=\"100%\" border=\"0\">");
                for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                {
                    sb.Append("<tr class=\"leftline\">");
                    sb.Append("<td valign=\"top\" colspan=\"2\">");
                    sb.Append("<a href=\"Article/Article.aspx?Id=" + ds.Tables[0].Rows[i]["OrderId"].ToString() + ".aspx\">&nbsp; " + ds.Tables[0].Rows[i]["ArtTitle"].ToString() + "</a>");
                }
                sb.Append("</td>");
                sb.Append("</tr>");
                sb.Append("</table>");
            }
            return sb.ToString();
        }
        //频道13, 人物访谈
        public string getArticlePeople()
        {
            StringBuilder sb = new StringBuilder();
            DataSet ds = DbHelperSQL.Query("select top 8 * from Fjaspx_Article where catId in(select OrderId from Fjaspx_ArticleCategory where ChannelId=13) order by artDate desc ");
            if (ds.Tables[0].Rows.Count > 0)
            {
                sb.Append("<table cellspacing=\"3\" cellpadding=\"0\" width=\"100%\" border=\"0\">");
                for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                {
                    sb.Append("<tr class=\"leftline\">");
                    sb.Append("<td valign=\"top\" colspan=\"2\">");
                    sb.Append("<a href=\"Article/Article.aspx?Id=" + ds.Tables[0].Rows[i]["OrderId"].ToString() + ".aspx\">&nbsp; " + ds.Tables[0].Rows[i]["ArtTitle"].ToString() + "</a>");
                }
                sb.Append("</td>");
                sb.Append("</tr>");
                sb.Append("</table>");
            }
            return sb.ToString();
        }
        //热点栏目导航
        public string HotChannel()
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i <= 20; i++)
            {
                sb.Append("<font color=\"#4d8ab3\">编程</font><font color=\"#4d8ab3\">&nbsp;</font>");
            }
            return sb.ToString();
        }

    }
}